package com.guoteng.androidlearn;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhaoguoteng on 2017/1/20.
 */

public class ActivityCollector {

    public static List<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {

        activities.remove(activity);
    }

    public static void finishAll() {

//        for (int i = 0; i < activities.size(); i++) {
//
//            Activity activity = activities.get(i);
//            activity.finish();
//        }

        for (Activity activity: activities) {

            if (!activity.isFinishing()) {

                activity.finish();
            }
        }

    }
}
